<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
	
<%@ include file="../common/css.jsp"%>
<%@ include file="../common/js.jsp"%>
<link type="text/css" rel="stylesheet" href="/css/v4/channel.css"/>
<link type="text/css" rel="stylesheet" href="/css/v4/detail.css"/>
<!--[if ie 6]><script src="../../js/v4/iepng.js" type="text/javascript"></script><![endif]-->
<!--[if ie]><link href="../../css/v4/common/IE.css" type="text/css" rel="stylesheet"><![endif]-->
<script type="text/javascript">
	var productList = new Array();
	$(function() {

		$.fn.popDiv({tcID : "share_link", opacity : 0.4, isZZ : true, speed : 0, noResize : true });
		//通过链接抓取商品
		$("#product_submit").click(
				function() {
					var linkUrl = $("#link_url").val();
					if (IsNull(linkUrl)) {
						alert("请填写商品地址");
						return;
					}
					if (linkUrl.indexOf("item.taobao.com") != -1
							|| linkUrl.indexOf("tmall.com") != -1
							|| linkUrl.indexOf("ershou.taobao.com") != -1
							|| linkUrl.indexOf("360buy.com") != -1
							|| linkUrl.indexOf("auction1.paipai.com") != -1
							|| linkUrl.indexOf("auction2.paipai.com") != -1
							|| linkUrl.indexOf("product.dangdang.com") != -1
							|| linkUrl.indexOf("item.vancl.com") != -1) {
						loading();
						$.post("/donigProductInfo.htm", {
							linkUrl : linkUrl
						}, function(data) {
							if (!IsNull(data) && IsNull(data.error)) {
								//如果此商品已经被分享过了
								if(data.result == "contain"){
									$("#share_link").html($("#share_result").html());
									$("#share_link").find("#share_result_pic").attr("src",data.imageServer+data.picThumb+'_200x200.jpg');
									$("#share_link").find("#share_result_title").text(data.name);
									$("#share_link").find("#share_result_discuss").find("a").attr("href","/shop/go.htm?pid="+data.identifier);
									$("#share_link").find("#share_result_discuss").show();
								}else{
									$("#share_link").html($("#share_xinde").html());
									//如果有图片列表
									if(data.imgs.length > 1){
										var imgsLi = "";
										for(var i=0; i<data.imgs.length; i++){
											if(i == 0){
												imgsLi += '<li style="display:block;" value="'+i+'"><img src="'+data.imgs[i].url+'" class="block" width="182" height="182"/></li>';
											}else{
												imgsLi += '<li style="display:none;" value="'+i+'"><img src="'+data.imgs[i].url+'" class="block" width="182" height="182"/></li>';
											}
										}
										$("#share_link").find("#share_xinde_imgs").html(imgsLi);
									}else{
										$("#share_link").find("#share_xinde_pic").attr("src",data.picUrl);
										$("#share_link").find("#share_xinde_next").remove();
									}
									$("#share_link").find("#share_xinde_title").text(data.name);
									$("#share_link").find("#share_xinde_price").text("￥"+data.price);
								}
								$.fn.popDiv({tcID : "share_link", opacity : 0.4, isZZ : true, noResize : true, speed : 0 });
								//添加进商品集合
								productList.push(data);
							} else {
								alert("获取商品失败，请换一个商品试试");
							}
						}, "json");
					} else {
						alert("请填写正确的商品地址");
					}

				});
		
	});
	//分享商品产生微博
	function shareproduct(){
		var share = $("#textarea_share").val();
		if(share.length > 140){
			alert("最多可以输入140个字，您输入的太多了");
			return ;
		}else{
			productList[0].picUrl = $("#share_xinde_imgs").find("li:visible:first").find("img:first").attr("src");
			$("#share_xinde_button").unbind("click");
			loading();
			$.post("/shareproduct.htm", {
				'content' : share,
				'productList' : escape($.toJSON(productList)),
				'isShare' : false
			}, function(data) {
				if(data.msg == "success"){
					//如果是话题微博页面
					if(location.href.indexOf("discussdoing.htm") != -1){
						$.post("/misc/album/pushtoalbum.htm",{
							pictorialIds : $("#discussdoing_pictorialId").val(),
							doingIds : data.code
						});
					}
					$("div.zz_box").hide();
					$("div.tc_box").hide();
					luckRank();
				}
			}, "json");
		}
	}

	//浏览图片列表
	function browsePic(self) {
		var text = $(self).text();
		var ul = $(self).parent().parent().find("ul:first");
		var li = $(ul).find("li:visible:first");
		var liNo = $(li).attr("value");
		var liSize = ul.find("li").size();
		$(ul).find("li").hide();
		if (text == "下一张>") {
			//如果已经到了最后一张
			if ((liNo + 1) == liSize) {
				$(ul).find("li:first").show();
			} else {
				$(ul).find("li::eq(" + (liNo + 1) + ")").show();
			}
		} else {
			//如果是第一张
			if (liNo == 0) {
				$(ul).find("li::eq(" + (liSize - 1) + ")").show();
			} else {
				$(ul).find("li::eq(" + (liNo - 1) + ")").show();
			}
		}
	}
	//输入字数
	function remain(textarea, remain, max){
		$("#" + remain).show();
		var content = $("#" + textarea).val();
		//取得用户输入的字符长度
		var length = content.length;
		if (length <= max) {
			$("#" + remain)
					.html("<i>" + (max - length)
									+ "</i>/"+140);
			return true;
		} else {
			$("#" + remain).html(
					"&nbsp;超出 <font size='3'color='red' id='remain'>" + (length - max)
							+ "</font> 字");
			return false;
		}
	}
	//等待
	function loading(){
		
	}
</script>
<%-- 分享链接的弹出框 --%>
<div class="tc_box release_box" id="share_link">
	<div class="release_title">
		<a href="javascript:void(0);" class="tc_close close_btn">关闭</a>
		<p>
			分享一件商品给更多妈妈
		</p>
	</div>
	<div class="content clearfix" id="share_link_content">
		<div class="rel_box1">
			<div class="release_det">
				<p class="tip">
					商品链接<span>粘贴商品的网址到下面框中即可</span>
				</p>
				<input type="text" class=" focus rel_text" id="link_url" /> <input
					type="button" value="确 定" class="def_btn_s2" id="product_submit" />
			</div>
			<div class="support">
				<p>已支持以下平台：</p>
				<div class="share_link">
					<a href="http://www.taobao.com/" target="_blank" rel="nofollow"><i
						class="icon_bg tb"></i>淘宝</a> <a href="http://www.360buy.com/"
						target="_blank" rel="nofollow"><i class="icon_bg jd"></i>京东</a> <a
						href="http://www.paipai.com/" target="_blank" rel="nofollow"><i
						class="icon_bg pp"></i>拍拍</a> <a href="http://www.dangdang.com/"
						target="_blank" rel="nofollow"><i class="icon_bg dd"></i>当当</a> <a
						href="http://www.vancl.com/" target="_blank" rel="nofollow"><i
						class="icon_bg vancl"></i>凡客</a>
				</div>
			</div>
		</div>
		<div class="rel_box2">
			<img src="../../images/v4/other/other_1.png" class="pro_address" />
		</div>
	</div>
</div>
<%-- 分享心得弹出框 --%>
<div class="tc_box release_box" id="share_xinde" style="display: none;">
	<div class="release_title">
		<a href="javascript:void(0);" class="tc_close close_btn">关闭</a>
		<p>分享一件商品给更多妈妈</p>
	</div>
	<div class="content clearfix" id="share_link_content">
		<div class="rel_box2">
			<div class="rel_pic_box">
				<div class="rel_pic_head clearfix">商品图片</div>
				<ul class="rel_pic_det" id="share_xinde_imgs">
					<li><img src="" class="block" width="182" height="182" id="share_xinde_pic" />
					</li>
				</ul>
				<div class="rel_fy clearfix" id="share_xinde_next">
					<a href="javascript:void(0);" onclick="browsePic(this)"
						class="fr mr10">下一张&gt;</a><a href="javascript:void(0);"
						onclick="browsePic(this)" class="fl ml5">&lt;上一张</a>
				</div>
			</div>
		</div>
		<div class="rel_box1">
			<div class="rel_pro_det">
				<a class="title" id="share_xinde_title">年中大促3.8折2012新款夏装童装大女童短袖上衣立体花朵公主T恤</a>
				<span id="share_xinde_price" class="price">￥49.00</span>
				<div class="write_box">
					<textarea autocomplete="off" onkeyup="remain('textarea_share','doing_content_error',140)" onkeydown="remain('textarea_share','doing_content_error',140)" id="textarea_share"></textarea>
					<div class="face_box">
						<span class="fr mr10" id="doing_content_error"><i>0</i>/140</span>
						<!-- <a href="#" class="face_link"><img src="../../images/v4/other/icon_5.png" />表情</a> -->
					</div>
				</div>
				<div class="clear"></div>
				<div>
					<input type="button" value="分 享" id="share_xinde_button" onclick="shareproduct()" class="def_btn_s2">
				</div>
			</div>
		</div>

	</div>
</div>
<%-- 分享失败/成功弹出框 --%>
<div class="tc_box release_box" id="share_result" style="display: none;">
	<div class="release_title">
		<a href="javascript:void(0);" class="tc_close close_btn">关闭</a>
		<p>分享一件商品给更多妈妈</p>
	</div>
	<div class="content clearfix">

		<div class="rel_box1">
			<div class="rel_share">
				<a class="title" id="share_result_title">年中大促3.8折2012新款夏装童装大女童短袖上衣立体花朵公主T恤</a>
				<p class="share_result" id="share_result_answer">您分享的这个商品已经有其他妈妈分享过了</p>
				<div class="rest_ope" id="share_result_discuss" style="display: none;">
					你可以对这个商品<a href="javascript:void(0);" class="def_btn_s2" target="_blank">点 评</a>
				</div>
				<div class="rest_ope" id="share_result_ok" style="display: none;">
					<a href="javascript:void(0);" class="tc_close def_btn_s5">确定</a>
				</div>
			</div>
		</div>
		<div class="rel_box2">
			<div class="rel_pic_box">
				<div class="rel_pic_head clearfix">商品图片</div>
				<ul class="rel_pic_det" id="share_result_imgs">
					<li><img src="../../images/v4/other/pro_182x182.png"
						class="block" width="182" height="182" id="share_result_pic" />
					</li>
				</ul>
			</div>
		</div>
	</div>
</div>

<div class="zz_box"></div>